
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       sensor_rf_benewake.h
  * @author     baiyang
  * @date       2023-2-9
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include "sensor_rf_backend_serial.h"
/*-----------------------------------macro------------------------------------*/
#ifndef MB_RANGEFINDER_BENEWAKE_ENABLED
#define MB_RANGEFINDER_BENEWAKE_ENABLED MB_RANGEFINDER_ENABLED
#endif

#if MB_RANGEFINDER_BENEWAKE_ENABLED
/*----------------------------------typedef-----------------------------------*/
typedef struct sensor_rf_benewake* sensor_rf_benewake_t;
typedef const struct sensor_rf_benewake* sensor_rf_benewake_const_t;
typedef struct sensor_rf_benewake_ops* sensor_rf_benewake_ops_t;

struct sensor_rf_benewake {
    struct sensor_rf_backend_ser backend;

    sensor_rf_benewake_ops_t     ops_benewake;

    uint8_t linebuf[10];
    uint8_t linebuf_len;
};

struct sensor_rf_benewake_ops {
    float (*model_dist_max_cm)(sensor_rf_backend_const_t rf_backend);
    bool (*has_signal_byte)(sensor_rf_backend_const_t rf_backend);
};
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void sensor_rf_backend_benewake_ctor(sensor_rf_benewake_t rf_backend_benewake,
                                    sensor_rf_benewake_ops_t _ops_benewake,
                                    sensor_rf_backend_ser_ops_t _ops_ser,
                                    sensor_rf_backend_ops_t _ops,
                                    sensor_rf_state_t _state, sensor_rf_params_t _params,
                                    const char *name);

void sensor_rf_bind_backend_ser_function(sensor_rf_backend_ser_ops_t ops_frontend, sensor_rf_backend_ser_ops_t ops_backend);

static inline float sensor_rf_model_dist_max_cm(sensor_rf_backend_t rf_backend) {
    RT_ASSERT(((sensor_rf_benewake_const_t)rf_backend)->ops_benewake->model_dist_max_cm != NULL);
    return ((sensor_rf_benewake_const_t)rf_backend)->ops_benewake->model_dist_max_cm(rf_backend);
}

static inline bool sensor_rf_has_signal_byte(sensor_rf_backend_t rf_backend) {
    if (((sensor_rf_benewake_const_t)rf_backend)->ops_benewake->has_signal_byte != NULL) {
        return ((sensor_rf_benewake_const_t)rf_backend)->ops_benewake->has_signal_byte(rf_backend);
    }

    return false;
}
/*------------------------------------test------------------------------------*/
#endif  // MB_RANGEFINDER_BENEWAKE_ENABLED

#ifdef __cplusplus
}
#endif



